package com.party.core.service.member.biz;

import com.party.common.utils.StringUtils;
import com.party.core.model.member.Member;
import com.party.core.model.member.PartnerMember;
import com.party.core.service.member.IMemberService;
import com.party.core.service.member.IPartnerMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: party
 * @description: 机构用户业务
 * @author: Hua Qunhao
 * @create: 2019-08-19 16:27
 **/
@Service
public class PartnerMemberToBizService {
    @Autowired
    private IMemberService memberService;
    @Autowired
    private IPartnerMemberService partnerMemberService;

    /**
     * @Description:
     * @Param: [partnerId, memberId, mobile]
     * @return: boolean
     * @Author: Hua Qunhao
     * @Date: 2019/8/19
     */
    public boolean checkPartnerUser(String partnerId, String memberId, String mobile) {
        List<Member> members = memberService.checkUserName("mobile", mobile, "", Member.MEMBER_PERSONAL);
        boolean bt = false;
        if (members.size() == 0) {
            bt = true;//手机号不存在
        } else {
            Member member = members.get(0);
            PartnerMember byPartnerAndMember = partnerMemberService.findByPartnerAndMember(partnerId, member.getId());
            if (byPartnerAndMember == null) {
                if (StringUtils.isEmpty(memberId)) {
                    bt = false; //通过手机号查询的用户 和当前机构有关系
                } else {
                    if (member.getId().equals(memberId)) {
                        bt = true; //通过手机号查询的用户 和当前保存的用户 是同一个
                    }
                }
            } else {
                if (StringUtils.isEmpty(memberId)) {
                    bt = false; //通过手机号查询的用户 和当前机构有关
                } else {
                    if (member.getId().equals(memberId)) {
                        bt = true; //通过手机号查询的用户 和当前保存的用户 是同一个
                    }
                }
            }
        }
        return bt;

/*        Map<String, Object> mmp = Maps.newHashMap();
        mmp.put("isRelated", false);//是否有关系
        mmp.put("isSave", true);//是否可以保存
        List<Member> members = memberService.checkUserName("mobile", mobile, "", Member.MEMBER_PERSONAL);

        if (members.size() > 0) {
            Member member = members.get(0);
            PartnerMember byPartnerAndMember = partnerMemberService.findByPartnerAndMember(partnerId, member.getId());
            if (byPartnerAndMember != null) {
                if (StringUtils.isNotEmpty(memberId)) {
                    if (member.getId().equals(memberId)) {  //通过手机号查询出来的 用户 和 当前机构 是否存在关系
                        mmp.put("isRelated", true);//是否有关系
                        mmp.put("isSave", true);//是否可以保存
                        return mmp;
                    }
                }else{

                }
            } else {
                if (StringUtils.isNotEmpty(memberId)) {
                    mmp.put("isRelated", false);//是否有关系
                    mmp.put("isSave", false);//是否可以保存
                    return mmp;
                }
            }
        }
        return mmp;*/
    }
}
